/**
 * 
 */
package imoney.client.handler;

import com.google.gwt.event.dom.client.FocusEvent;
import com.google.gwt.event.dom.client.FocusHandler;
import com.google.gwt.user.client.ui.TextBox;

/**
 * This handler empties the TextBox when the mouse is down.
 * @author Arnaud PELOQUIN
 *
 */
public class FocusEmptyText implements FocusHandler {

	private TextBox text;
	private String content;
	
	/**
	 * Empty the textBox if the content is default content.
	 * @param tbox : the text widget to clear.
	 * @param prefilContent
	 */
	public FocusEmptyText(TextBox tbox, String prefilContent) {
		text = tbox;
		content = prefilContent;
	}

	/**
	 * Empty the TextBox if the content is the default prefil text.
	 * If not, does nothing.
	 */
	@Override
	public void onFocus(FocusEvent event) {
		text.setVisibleLength(text.getMaxLength());
		text.selectAll();
		String currentTxt = text.getText();
		if(currentTxt.equals(content)) {
			text.setText("");
		}
	}
}
